package com.jwdf.uda.utils;

import android.os.Environment;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * Created by Administrator on 2016/11/21.
 */
public class ImageProcessing {

    public static File createTempImageFile(String imageType) throws IOException {
        // Create an image file name
        String imageFileName = "temp"+ UUID.randomUUID();
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        if (!storageDir.exists()) {
            if (!storageDir.mkdir()) {
                throw new IOException();
            }
        }
        File image = new File(storageDir, imageFileName + imageType);
        return image;
    }


    public static File createTempImageFile(String imageType,File imageFileName) throws IOException {
        File image = new File(imageFileName + imageType);
        return image;
    }


    public synchronized static String getImageType(String uri) {
        String[] array = uri.split("\\.");
        return "." + array[array.length - 1].toLowerCase();
    }
}
